package com.dgcsxy.cat_eyes_movies.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dgcsxy.cat_eyes_movies.common.utils.ResponseResult;
import com.dgcsxy.cat_eyes_movies.dao.MoviesMapper;
import com.dgcsxy.cat_eyes_movies.entity.dto.MoviesDto;
import com.dgcsxy.cat_eyes_movies.entity.pojo.Movies;
import com.dgcsxy.cat_eyes_movies.service.MoviesService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author rokies
 * @DATE 2022/6/16 16:35
 * @Version 1.0
 */
@Service
public class MoviesServiceImpl extends ServiceImpl<MoviesMapper, Movies> implements MoviesService {

    private final MoviesMapper moviesMapper;

    public MoviesServiceImpl(MoviesMapper moviesMapper) {
        this.moviesMapper = moviesMapper;
    }

    @Override
    public ResponseResult queryMoviesByName(String movieName) {
        Movies movies = moviesMapper.queryMoviesByName(movieName);
        if(movies==null){
            return ResponseResult.FAILED("查无此电影");
        }
        return ResponseResult.SUCCESS(movies);
    }

    @Override
    public ResponseResult queryMoviesByPage(int page,int pageSize) {
        if (page <= 0 || pageSize <= 0) {
            return ResponseResult.FAILED();
        }
        Page<MoviesDto> pages = new Page<>(page, pageSize);
        IPage<MoviesDto> moviesDtoIPage = moviesMapper.queryMoviesByPage(pages);
        return moviesDtoIPage != null ? ResponseResult.SUCCESS(moviesDtoIPage) : ResponseResult.FAILED();
    }
}
